import { getUserLeave } from 'services/app';

export default {
    namespace: 'leave',
    state: {
        pageIndex: 1,
        pageCount: 10,
        keywords: '',
        records: [],
        total: 0,
    },
    effects: {
        *getLeaves ({ payload }, { call, put }) {
            const {pageIndex, pageCount, keywords} = payload;
            const rsp = yield call(getUserLeave, payload);
            const {total, data} = rsp;
            yield put({
                type: 'save',
                payload:{
                    pageIndex,
                    pageCount,
                    keywords,
                    records: data,
                    total,
                },
            });
        },
    },

    reducers: {
        save (state, { payload }) {
            return { ...state, ...payload };
        },
    },
};
